package com.pf.controller;

import com.pf.dto.BaseResult;
import com.pf.dto.UserDTO;
import com.pf.utils.BaseResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2021/9/6
 */
@Slf4j
@RestController
public class IndexController {

    @GetMapping("/get")
    public BaseResult<UserDTO> get(@RequestParam("requestId") String requestId,
                                   @RequestParam("accessToken") String accessToken,
                                   @RequestParam("userId") Integer userId) {
        log.info(">>>>>> IndexController - get 参数：requestId={},accessToken={},userId={}", requestId, accessToken, userId);
        UserDTO userDTO = UserDTO.builder().userId(userId).userName("张三").userPwd("123").build();
        return BaseResultUtils.success(userDTO);
    }

    /**
     * http://localhost:8080/get2?requestId=1&accessToken=2
     * <p>
     * Content-type = multipart/form-data
     *
     * @param requestId
     * @param accessToken
     * @param userDTO
     * @return
     */
    @GetMapping("/get2")
    public BaseResult<UserDTO> get2(@RequestParam("requestId") String requestId,
                                    @RequestParam("accessToken") String accessToken,
                                    UserDTO userDTO) {
        log.info(">>>>>> IndexController - get2 参数：requestId={},accessToken={},userDTO={}", requestId, accessToken, userDTO);
        return BaseResultUtils.success(userDTO);
    }


    /**
     * http://localhost:8080/post?requestId=1&accessToken=2
     * Content-type = application/json
     * {
     * "userId":1001,
     * "userName":"张三"
     * }
     *
     * @param requestId
     * @param accessToken
     * @param userDTO
     * @return
     */
    @PostMapping("/post")
    public BaseResult post(@RequestParam("requestId") String requestId,
                           @RequestParam("accessToken") String accessToken,
                           @RequestBody UserDTO userDTO) {
        log.info(">>>>>> IndexController-post 参数：requestId={},accessToken={},userDTO={}", requestId, accessToken, userDTO);
        return BaseResultUtils.success();
    }

    /**
     * http://localhost:8080/post2?requestId=1&accessToken=2
     * content-type = application/x-www-form-urlencoded
     * <p>
     * userId = 1001
     * userName = 李四
     *
     * @param requestId
     * @param accessToken
     * @param userDTO
     * @return
     */
    @PostMapping("/post2")
    public BaseResult post2(@RequestParam("requestId") String requestId,
                            @RequestParam("accessToken") String accessToken,
                            UserDTO userDTO) {
        log.info(">>>>>> IndexController-post2 参数：requestId={},accessToken={},userDTO={}", requestId, accessToken, userDTO);
        return BaseResultUtils.success();
    }
}
